import keras
from keras import layers
import numpy as np
import pandas as pd
from matplotlib import pyplot as plt
from keras.utils import np_utils

data = pd.read_csv("dataset/iris_training.csv", header=0)
data.columns = ['l1', 'l2', 'l3', 'l4', 'lei']

data = np.array(data)
x_train = data[:110, :-1]
y_train = data[:110, -1]
x_test = data[110:, :-1]
y_test = data[110:, -1]

mean = x_train.mean(axis=0)
std = x_train.std(axis=0)
x_train = (x_train - mean) / std

mean = x_test.mean(axis=0)
std = x_test.std(axis=0)
x_test = (x_test - mean) / std

y_train = np_utils.to_categorical(y_train, num_classes=3)
y_test = np_utils.to_categorical(y_test, num_classes=3)

model = keras.Sequential()
model.add(layers.Dense(16, input_dim=4, activation='relu'))
model.add(layers.Dense(3, activation='softmax'))

model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['acc'])

history = model.fit(x_train, y_train, epochs=300, verbose=1, batch_size=16, validation_split=0.01)

plt.plot(history.history.get('loss'))
plt.plot(history.history.get('acc'))
plt.legend(["loss", "acc"])
plt.show()
